package org.myorg.v6;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.myorg.v4.FPeople4;

public class MountainRecord implements Record {
	
	
	protected static final Log LOG = LogFactory.getLog(MountainRecord.class);
	public Integer length = new Integer(0);
	public Integer pos = new Integer(0);

	public Long t1 = new Long(0);
	public Long itr = new Long(0);
	public Double[] data = new Double[0];
	

	public Double[] value = new Double[0];
	public Long[] it = new Long[0];
	public Long[] time = new Long[0];
	
	public MountainRecord() {
		t1 = System.currentTimeMillis();
	}
	
	public MountainRecord(Double[] data) {
		
		LOG.debug("initial pos is " + pos + "length is " + data.length);
		
		this.length = data.length;
		this.data = data;
		value = new Double[length];
		it = new Long[length];
		time = new Long[length];
		t1 = System.currentTimeMillis();
	}
	public MountainRecord(MountainRecord r) {
		this.length = r.length;
		this.pos = r.pos;
		this.data = r.data;

		value = r.value;
		it = r.it;
		time = r.time;
		
		t1 = r.t1;
		this.itr = r.itr;
	}
	
	@Override
	public void record(FPeople4 p) {
		// TODO Auto-generated method stub
		
		LOG.debug("itr is " + itr + " pos is " + pos + " length is " + length );
		
		itr++;
		while (pos < length && p.getBest().getFitness() >= data[pos]) {
			
			LOG.info("record, pos is " + pos + "length is " + length);
			
			value[pos] = new Double(p.getBest().getFitness());
			it[pos] = itr;
			time[pos] = System.currentTimeMillis() - t1;
			pos++;
		}
	}
	@Override
	public boolean isCompleted() {
		// TODO Auto-generated method stub
		return (pos==length)?true:false;
	}
	

}
